import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    name: "张三",
    age: 10,
    msg: "这是对张三的介绍",

  },
  getters: {
    changeAge(state) {
      return state.age < 18 ? 18 : state.age;
      // if(state.age<18){
      //   return 18
      // }else{
      //   return state.age
      // }
    }
  },
  mutations: {
    changeName(state, name) {
      // console.log(state);
      state.name = name
    },
    changeMsg(state, msg) {
      state.msg = msg
    }
  },
  actions: {
    //异步操作
    yibu(context, payload) {
      setTimeout(() => {
        context.commit("changeMsg", payload)
      }, 3000);
    }
  },
  modules: {
    a: {
      state: {
        name: "AAAAA"
      },
      getters:{},
      mutations:{},
      actions:{}
    },
    b: {
      state: {
        name: "BBBB"
      }
    }
  }
})
